import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {

    public static void main(String[] args) {
        // 记录信息
        StringBuffer buffer = new StringBuffer();

        HttpURLConnection conn = null;
        try {
            URL url = new URL("http://www.bhzyxy.net/xyxw/tzgg.htm");
            conn = (HttpURLConnection) url.openConnection();
            // 设置请求的属性
            conn.setDoOutput(true); // 是否可以输出
            conn.setRequestMethod("GET"); // 请求方式, 只包含"GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE"六种
            conn.setConnectTimeout(60000); // 最高超时时间
            conn.setReadTimeout(60000); // 最高读取时间
            conn.setConnectTimeout(60000); // 最高连接时间
            // 读取数据
            InputStream is = null;
            InputStreamReader inputReader = null;
            BufferedReader reader = null;
            try {
                is = conn.getInputStream();
                inputReader = new InputStreamReader(is, "UTF-8");
                reader = new BufferedReader(inputReader);
                String temp;
                while ((temp = reader.readLine()) != null) {
                    buffer.append(temp);
                }
            } catch (Exception e) {
                System.out.println("HttpGetUtils doGetNoParameters error: " + e);
            } finally {
                try {
                    if (reader != null) {
                        reader.close();
                    }
                    if (inputReader != null) {
                        inputReader.close();
                    }
                    if (is != null) {
                        is.close();
                    }
                } catch (IOException e) {
                    System.out.println("HttpGetUtils doGetNoParameters error: " + e);
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 当http连接空闲时, 释放资源
            if (conn != null) {
                conn.disconnect();
            }
        }
        // 返回信息
        System.out.println(buffer.toString());
        if(buffer.toString().contains("你关注的关键字")){
            //继续解析
            //提取连接，然后已某种方式放到你能关注到的媒介
        }
    }

}